package com.bb.blog.security.common;

import com.bb.blog.web.component.ResponseUtil;
import com.bb.blog.web.model.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Slf4j
public class CommonFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        log.info("=======  认证失败  =======",exception);
        CommonResponse data = ResponseUtil.fail(HttpStatus.BAD_REQUEST,"认证失败");
        ResponseUtil.parseResponse(response, data);
    }
}
